"""扫描问题Schema"""
from typing import Optional, Dict, Any
from pydantic import BaseModel, Field
from datetime import datetime


class IssueBase(BaseModel):
    """扫描问题基础Schema"""
    record_id: int = Field(..., description="扫描记录ID")
    issue_number: str = Field(..., description="问题编号", max_length=50)
    rule_name: str = Field(..., description="规则名称", max_length=200)
    level: str = Field(..., description="级别: critical/warning/info")
    file_path: str = Field(..., description="文件路径", max_length=500)
    line_number: Optional[int] = Field(None, description="行号")
    description: str = Field(..., description="问题描述")
    code_snippet: Optional[str] = Field(None, description="主要代码片段")


class IssueCreate(IssueBase):
    """创建扫描问题Schema"""
    pass


class IssueUpdate(BaseModel):
    """更新扫描问题Schema"""
    confirm_status: Optional[str] = Field(None, description="确认状态")
    confirm_type: Optional[str] = Field(None, description="确认类型")
    confirmed_by: Optional[str] = Field(None, description="确认人")
    confirm_comment: Optional[str] = Field(None, description="确认备注")


class IssueConfirmRequest(BaseModel):
    """确认问题请求Schema"""
    confirm_type: str = Field(..., description="确认类型: problem/falsePositive/fixed/known")
    confirmed_by: str = Field(..., description="确认人", max_length=100)
    confirm_comment: Optional[str] = Field(None, description="确认备注")


class IssueResponse(IssueBase):
    """扫描问题响应Schema"""
    id: int
    confirm_status: str = "unconfirmed"
    confirm_type: Optional[str] = None
    confirmed_by: Optional[str] = None
    confirmed_at: Optional[datetime] = None
    confirm_comment: Optional[str] = None
    inherited_from_id: Optional[int] = None
    created_at: datetime
    updated_at: datetime
    # 扩展字段数据
    extension_data: Optional[Dict[str, Any]] = Field(None, description="扩展字段数据")

    class Config:
        from_attributes = True

